package com.ruoyi.web.controller.textToClass;

import com.ruoyi.TextToClasses.domain.ClassText;
import com.ruoyi.TextToClasses.service.IClassTextService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 中间表管理Controller
 * 
 * @author ruoyi
 * @date 2024-11-30
 */
@RestController
@RequestMapping("/TextToClasses/TextToClass")
public class ClassTextController extends BaseController
{
    @Autowired
    private IClassTextService classTextService;

    /**
     * 查询中间表管理列表
     */
    @PreAuthorize("@ss.hasPermi('TextToClasses:TextToClass:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClassText classText)
    {
        startPage();
        List<ClassText> list = classTextService.selectClassTextList(classText);
        return getDataTable(list);
    }

    /**
     * 导出中间表管理列表
     */
    @PreAuthorize("@ss.hasPermi('TextToClasses:TextToClass:export')")
    @Log(title = "中间表管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClassText classText)
    {
        List<ClassText> list = classTextService.selectClassTextList(classText);
        ExcelUtil<ClassText> util = new ExcelUtil<ClassText>(ClassText.class);
        util.exportExcel(response, list, "中间表管理数据");
    }

    /**
     * 获取中间表管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('TextToClasses:TextToClass:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(classTextService.selectClassTextById(id));
    }

    /**
     * 新增中间表管理
     */
    @PreAuthorize("@ss.hasPermi('TextToClasses:TextToClass:add')")
    @Log(title = "中间表管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClassText classText)
    {
        return toAjax(classTextService.insertClassText(classText));
    }

    /**
     * 修改中间表管理
     */
    @PreAuthorize("@ss.hasPermi('TextToClasses:TextToClass:edit')")
    @Log(title = "中间表管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClassText classText)
    {
        return toAjax(classTextService.updateClassText(classText));
    }

    /**
     * 删除中间表管理
     */
    @PreAuthorize("@ss.hasPermi('TextToClasses:TextToClass:remove')")
    @Log(title = "中间表管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(classTextService.deleteClassTextByIds(ids));
    }
}
